﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using V5_Common;
using System.Data;
using V5_BLL;
using V5_Model;

namespace V5_EShop.Admin.ProductExpand {
    public partial class Admin_ProductAnswer : System.Web.UI.Page {
        int askID = 0;
        protected void Page_Load(object sender, EventArgs e) {
            askID = InputHelper.SetNumber(Request["askid"]);
            if (!this.IsPostBack) {
                Bind_DataList();
            }
        }


        private void Bind_DataList() {
            this.MultiViewList.ActiveViewIndex = 0;
            int Count = 0;
            string strWhere = " askid=" + askID;

            DataTable dt = new BLLProductAnswer().GetList(
                Pager.PageSize,
                Pager.CurrentPageIndex,
                strWhere,
                " ID Desc",
                ref Count).Tables[0];
            this.Pager.RecordCount = Count;
            this.gvList.DataSource = dt;

            this.gvList.DataBind();
        }


        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="oUserID"></param>
        /// <returns></returns>
        public ModelUser Get_User(object oUserID) {
            int UserID = InputHelper.SetNumber(oUserID);
            if (UserID > 0) {
                return new BLLUser().GetModel(UserID);
            }
            return null;
        }

        /// <summary>
        /// 获取产品信息
        /// </summary>
        /// <param name="oProductID"></param>
        /// <returns></returns>
        public ModelProduct Get_Product(object oProductID) {
            int ProductID = InputHelper.SetNumber(oProductID);
            if (ProductID > 0) {
                return new BLLProduct().GetModel(ProductID);
            }
            return null;
        }

        protected void Pager_PageChanged(object sender, EventArgs e) {
            this.Bind_DataList();
        }

        protected void gvList_RowCommand(object sender, GridViewCommandEventArgs e) {
            string eName = InputHelper.SetString(e.CommandName);
            int id = InputHelper.SetNumber(e.CommandArgument);
            switch (eName.ToLower()) {
                case "passed":
                    Bind_Passed(id);
                    break;
                case "del":
                    Bind_Delete(id);
                    break;
                default:
                    break;
            }
        }

        private void Bind_Passed(int id) {
            ModelProductAnswer model = new BLLProductAnswer().GetModel(id);
            if (model != null) {
                if (model.Passed == 1) {
                    model.Passed = 0;
                }
                else {
                    model.Passed = 1;
                }
                new BLLProductAnswer().Update(model);
            }
            this.Bind_DataList();
        }

        private void Bind_Delete(int id) {
            new BLLProductAnswer().Delete(id);
            this.Bind_DataList();
        }
    }
}